1. Field of the Invention
The present invention relates to a method for decoding instructions with a processor, and more specifically, to a method for decoding variable length instructions in an execution package in parallel.
2. Description of the Prior Art
Superscalar processors are becoming more and more popular in the field of computers. These processors are able to execute multiple instructions at a time in order to increase performance of the processor. A typical processor pipeline always has stages of fetch, decode, and execute. In addition, an assembler is needed to work in cooperation with the processor in order to arrange instructions in groups that can be executed in parallel. The job of the assembler is to create execution packages, which contain a number of instructions equal to or less than a degree of parallelism. The processor can then execute all of the instructions in an execution package in parallel.
Many processors use variable length instruction sets that contain instructions with a variety of different lengths. One advantage of variable length instructions is that less memory is used to store the instructions because the instructions are not longer than necessary, and do not need to conform to a single size. On the other hand, decoding these variable length instructions is a difficult task since there is no common length for each instruction, and the decoder needs to know exactly how long each instruction is in order to decode the instructions.
Please refer to FIG. 1. FIG. 1 is a block diagram of a variable length instruction 10 according to the prior art. The instruction 10 is divided into an identification segment 12 and an instruction segment 18. The identification segment 12 is further divided into a position indicator 14, which indicates whether the instruction 10 is a last instruction in an execution package, and a length indicator 16, which indicates the length of the instruction in bytes. For example, the length indicator 16 shows that the instruction 10 contains 3 bytes. The identification segment 12 is typically 4 bits or one byte long, and the instruction segment 18 contains the remaining length of the instruction 10.
Please refer to FIG. 2. FIG. 2 is a block diagram of an execution package 20 according to the prior art. The execution package contains three instructions 25, 30, 35, each of the instructions having an identical structure as that of instruction 10. As shown in identification segments 26, 32, 36, instructions 25, 30, 35 have respective lengths of 2 bytes, 4 bytes, and 3 bytes. Also, position indicators in the identification segments 26, 32 are light colored to signify that instructions 25, 30 are not last instructions in the execution package 20. On the other hand, a position indicator in the identification segment 36 is hatched to indicate that the instruction 35 is a last instruction in the execution package 20.
Please refer to FIG. 3. FIG. 3 is a flowchart of a method of assembling, fetching, and decoding variable length instructions in order to determine a total length of an execution package according to the prior art.
Step 100: Use the assembler to form groups of variable length instructions that can be executed in parallel by the processor;
Step 102: Use the assembler to pack a group of instructions into an execution package;
Step 104: Processor fetches next execution package;
Step 106:
Decode an identification segment of next instruction in the execution package; look at length indicator to determine length of instruction segment;
Step 108:
Add the length of this instruction to the total length of the current execution package;
Step 110:
Look at position indicator to determine if this is the last instruction in the execution package; if so, go to step 112; if not, go to step 106; and
Step 112: The total length of the execution package has been calculated.
A shortcoming of the prior art method is efficiency of the decoding process in steps 106, 108, and 110. Specifically, the processor decodes the instruction segment of one instruction at a time. This is repeated until the lengths of all instructions in the execution package have been calculated. In other words, the lengths of instructions in an execution package are calculated in series. Thus, a great deal of time is spent calculating the lengths of instructions one at a time.